// pages/order/meal.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    statusBarHeight: app.globalData.statusBarHeight,
    titleTop:0,
    menuButtonInfoHeight:0,
    menuButtonInfoTop:0,
    selectedCategoryIndex: 0, 
    category:[
      {
        id:1,
        title:'益力多系列'
      },
      {
        id:2,
        title:'鲜果茶'
      },
      {
        id:3,
        title:'卡式系列'
      },
      {
        id:4,
        title:'果蔬汁系列'
      },
      {
        id:5,
        title:'鲜榨果汁'
      },
      {
        id:6,
        title:'提示'
      }
    ],
    rpx160Height:'',
    rpx160RightScrollViewHeight:'',
    activeCategoryTitle:"",
    categoryGoodsList:[
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      },
      {
        title:"维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多维C柠檬益力多",
        describe:"喝起来黄柠檬清香味",
        price:14,
        discount_price:9.9
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    const WindowInfo=wx.getWindowInfo();
    console.log("WindowInfo",WindowInfo);
    const statusBarHeight = WindowInfo.statusBarHeight;
    this.setData({statusBarHeight:statusBarHeight});
    const menuButtonInfo=wx.getMenuButtonBoundingClientRect();
    console.log("statusBarHeight",statusBarHeight);
    console.log("menuButtonInfo",menuButtonInfo);
    const titleTop = menuButtonInfo.top - (menuButtonInfo.height - statusBarHeight) / 2;
    this.setData({titleTop:titleTop});
    this.setData({menuButtonInfoHeight:menuButtonInfo.height});
    this.setData({menuButtonInfoTop:menuButtonInfo.top});
    console.log("titleTop",titleTop);

    console.log(WindowInfo.safeArea);


        // 尝试加载PingFang SC字体
        /*
        wx.loadFontFace({
          family: 'PingFang SC',
          source: 'url("https://your-font-url.com/PingFangSC-Regular.ttf")',
          success: function(res) {
            console.log('字体加载成功', res.status)
          },
          fail: function(res) {
            console.log('字体加载失败', res)
          },
          complete: function(res) {
            console.log('字体加载完成', res)
          }
        })

        */
        this.setData({activeCategoryTitle:this.data.category[0].title});
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
this.setBottomTabColumnHeight();
  },
  async setBottomTabColumnHeight(){
    //var getBottomTabColumnHeightRes=await this.getBottomTabColumnHeight();
  },
  async setCategoryAreaHeight(){
    var getBlackAreaHeightRes=await this.getBlackAreaHeight();
    console.log("getBlackAreaHeightRes",getBlackAreaHeightRes);
    //var getBottomTabColumnHeightRes=await this.getBottomTabColumnHeight();
    
    var getBottomTabColumnHeightByStorageRes=await this.getBottomTabColumnHeightByStorage();
    console.log("getBottomTabColumnHeightByStorageRes",getBottomTabColumnHeightByStorageRes);
    var WindowInfo=wx.getWindowInfo();
    var listHeight=WindowInfo.windowHeight-getBlackAreaHeightRes.data-getBottomTabColumnHeightByStorageRes.data;
    console.log("listHeight",listHeight);
    var rpx160Height="calc("+listHeight+"px - 23rpx)";
    var rpx160RightScrollViewHeight="calc("+listHeight+"px - 23rpx - 23rpx)";
    this.setData({rpx160Height:rpx160Height});
    this.setData({rpx160RightScrollViewHeight:rpx160RightScrollViewHeight})
  },
  //获取顶部黑色区块高度
async getBlackAreaHeight(){
  return new Promise((resolve)=>{

    const query = wx.createSelectorQuery()
    query.select('#blackArea').boundingClientRect()
    query.selectViewport().scrollOffset();
    query.exec(function (res) {
        console.log("blackArea区域高度获取",res);
        var height=0;
        for(var i in res){
            if(res[i].id=="blackArea"){
              height=res[i].height;
              break;
              
            }
        }
        resolve({code:"success",data:height})
    });
    
  });
 
},
//获取底部tab栏高度
async getBottomTabColumnHeightByStorage(){
  var that=this;
    return new Promise((resolve)=>{
      var tabColumnHeight=wx.getStorageSync('tabColumnHeight');
      resolve({code:"success",data:tabColumnHeight})
    });
},
//获取底部tab栏高度
async getBottomTabColumnHeight(){
  var that=this;
  return new Promise((resolve)=>{

    const query = wx.createSelectorQuery().in(that.$wx)
    query.select('.tab-bar').boundingClientRect()
    query.selectViewport().scrollOffset();
    query.exec(function (res) {
        console.log("获取底部tab栏高度",res);
        var height=0;
        for(var i in res){
            if(res[i].id=="blackArea"){
              height=res[i].height;
              break;
              
            }
        }
        resolve({code:"success",data:height})
    });
    
  });
},
  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    if (typeof this.getTabBar === 'function' &&
    this.getTabBar()) {
      this.getTabBar().setData({
        selected: 1
      })
    }
    this.setCategoryAreaHeight();


    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
  // 添加点击事件处理函数
onCategoryClick(e) {
  const index = e.currentTarget.dataset.index;
  this.setData({
    selectedCategoryIndex: index,
    activeCategoryTitle:this.data.category[index].title
  });
}

  
})